<?php
require_once("perficature-utils.php");

if ( array_key_exists('service', $_GET) && array_key_exists('id', $_GET) && array_key_exists('ua', $_GET) ) {
	// See what other parsing services think this UA is.
	header("Content-Type: application/x-javascript");
	$service = $_GET['service'];
	$id = $_GET['id'];
	$ua = $_GET['ua'];

	$pbrowser = "not found";
	if ( "useragentstringcom" == $service ) {
		$pbrowser = getUADoubleCheck($ua);
	}
	else if ( "user-agent-string-info" == $service ) {
		$pbrowser = getUserAgentStringInfo($ua);
	}
	//else if ( "garykeith" == $service ) {
	//$pbrowser = getGaryKeith($ua);
	//}

	echo "document.getElementById('$id').innerHTML = '$pbrowser';\n";
}
else if ( array_key_exists('format', $_GET) && array_key_exists('ua', $_GET) ) {
	// Return the raw browser string.
	header("Content-Type: text/plain");
	if ( "xhr" == $_GET['format'] || "XHR" == $_GET['format'] || "Xhr" == $_GET['format'] ) {
		$pbrowser = parseUseragentHeader($_GET['ua']);
		echo "$pbrowser\n";
	}
}

// punt - requires POST and REFERER
function getGaryKeith($useragent) {
	$url = "http://browsers.garykeith.com/tools/agent-checker.asp?Submitted=yes&UserAgentToMatch=" . urlencode($useragent);
	$aResults = array();
	$cmd = "./fetchurl.cgi 'url=" . urlencode($url) . "'";
	exec($cmd, $aResults);
	$html = join("\n", $aResults);

	if ( ereg("(e)", $html, $regs) ) {
		$browser = $regs[1];
		return $html;
	}

	return "";
}

// punt - doesn't actually show any results ???
function getXtractpro($useragent) {
	$url = "http://useragent.xtractpro.com/Parse.aspx?q=" . urlencode($useragent) . "&submit=Parse";
	$aResults = array();
	$cmd = "./fetchurl.cgi 'url=" . urlencode($url) . "'";
	exec($cmd, $aResults);
	$html = join("", $aResults);
	if ( ereg("(dieTabelle.*<\/th>)", $html, $regs) ) {
		$s1 = $regs[1];
		if ( ereg(".*>(.*)<\/th>", $s1, $regs2) ) {
			return $regs2[1];
		}
	}

	return "";
}


?>
